<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<c:set value="recruit" var="moduleName" scope="request" />
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
		<title>在线申请 - 计划场地</title>
	</head>
	<body>
		<dict:dict type="province,city,district" var="provincecitydistrict" />
		<script type="text/javascript">
var provincecitydistrict = eval('('+'<%=application.getAttribute("provincecitydistrict")%>'+')');
		</script>
		<html:form action="/site/user/region.do" styleId="mainForm" method="POST" onsubmit="return checkedForm();">
			<input type="hidden" name="method" class="method" value="save" />
			<html:hidden property="id" />
			<html:hidden property="serial" />
			<html:hidden property="applyBaseId" />
			<html:hidden property="isExpected" />
			<html:hidden property="isCollected" />
			<html:hidden property="townId" />
			<input type="hidden" name="direction" id="direction" value="" />
			<div class="site-title">
				八、 计划场地状况
			</div>
			<br />
			<div class="div-content">
			<table class="table-layout">
				<tr class="tr-even">
					<td>
						申请单位申请投资&nbsp;&nbsp; 
						<span id="dropContainer_0"> <html:hidden property="provinceId" /> <select id="drop_0"></select> </span>省&nbsp;&nbsp; 
						<span id="dropContainer_1"> <html:hidden property="cityId" /> <select id="drop_1"></select> </span>市&nbsp;&nbsp;
						<span id="dropContainer_2"> <html:hidden property="districtId" /> <select id="drop_2"></select> </span>区/县&nbsp;&nbsp;
						<span class="required">*</span>
					</td>
				</tr>
				<tr class="tr-odd">
					<td>
						拟建斯柯达4S店的场地（建议提供两处以上场地供[上汽大众]选择）：
					</td>
				</tr>
				<tr class="tr-even">
					<td>
						场地地址：
						<html:text property="address" style="width:500px" /><span class="required">*</span>
					</td>
				</tr>
				<tr class="tr-odd">
					<td>
						可用土地面宽
						<html:text property="width" style="width:60px" styleId="regionWidth" onchange="calculateArea();" />
						米，可用土地径深
						<html:text property="depth" style="width:60px" styleId="regionDepth" onchange="calculateArea();" />
						米；面积：
						<html:text property="area" style="width:60px" styleId="regionArea" readonly="true" styleClass="input-readonly" />
						平方米<span class="required">*</span>
					</td>
				</tr>
				<tr class="tr-even">
					<td>
						土地来源：
						<html:radio property="sourceCode" value="1" />
						已购买&nbsp;&nbsp;
						<html:radio property="sourceCode" value="2" />
						已租赁&nbsp;&nbsp;
						<html:radio property="sourceCode" value="3" />
						意向购买&nbsp;&nbsp;
						<html:radio property="sourceCode" value="4" />
						意向租赁&nbsp;&nbsp;
						<html:radio property="sourceCode" value="5" />
						其他，请说明
						<html:text property="sourceOthers" style="width:500px" />
					</td>
				</tr>
				<tr class="tr-odd">
					<td>
						使用/租赁年限：
						<html:text property="fixedYear" styleId="fixedYear"/>
						年
					</td>
				</tr>
				<tr class="tr-even">
					<td>
						土地性质：
						<html:radio property="propertyCode" value="1" />
						工业用地&nbsp;&nbsp;
						<html:radio property="propertyCode" value="2" />
						商用用地&nbsp;&nbsp;
						<html:radio property="propertyCode" value="3" />
						农用用地&nbsp;&nbsp;
						<html:radio property="propertyCode" value="4" />
						其他，请说明
						<html:text property="propertyOthers" style="width:500px" />
					</td>
				</tr>
				<tr class="tr-odd">
					<td>
						建设方式：展厅部分（
						<html:radio property="isNewShowHall" value="1" />
						新建&nbsp;&nbsp;
						<html:radio property="isNewShowHall" value="0" />
						改建）、车间部分（
						<html:radio property="isNewWorkShop" value="1" />
						新建&nbsp;&nbsp;
						<html:radio property="isNewWorkShop" value="0" />
						改建）
					</td>
				</tr>
				<tr class="tr-even">
					<td>
						如果选择新建，该场地上是否存在其它建筑物：
					</td>
				</tr>
				<tr class="tr-odd">
					<td>
						<html:radio property="hasOtherBuilding" value="0" />
						不存在&nbsp;&nbsp;
						<html:radio property="hasOtherBuilding" value="1" />
						存在，请说明&nbsp;&nbsp;
						<html:text property="otherBuilding" style="width:500px" />
					</td>
				</tr>
				<tr class="tr-even">
					<td>
						是否有抵押或争议：
						<html:radio property="hasGuarantee" value="1" />
						是&nbsp;&nbsp;
						<html:radio property="hasGuarantee" value="0" />
						否
					</td>
				</tr>
				<tr class="tr-odd">
					<td>
						地方政策是否允许在该场地建设4S店：
						<html:radio property="isPolicyAllowed" value="1" />
						允许&nbsp;&nbsp;
						<html:radio property="isPolicyAllowed" value="0" />
						不允许
					</td>
				</tr>
				<tr class="tr-even">
					<td>
						备选地块位置示意图：
						<input type="button" value="添加" onclick="preAddRegionImage(1)" />
						<input type="button" value="点击查看示例图片" onclick="jQuery.popMsg(jQuery('#regionImage1'),'示例图片-备选地块位置示意图','721','494')" />
						<div id="divRegionImageFormContainer1"></div>
						<div id="divRegionImageContainer1"></div>
					</td>
				</tr>
				<tr class="tr-odd">
					<td>
						主要汽车市场及备选场地位置的电子地图：
						<input type="button" value="添加" onclick="preAddRegionImage(2)" />
						<input type="button" value="点击查看示例图片" onclick="jQuery.popMsg(jQuery('#regionImage2'),'示例图片-主要汽车市场及备选场地位置的电子地图','614','511')" />
						<div id="divRegionImageFormContainer2"></div>
						<div id="divRegionImageContainer2"></div>
					</td>
				</tr>
				<tr class="tr-even">
					<td>
						备选场地照片：
						<input type="button" value="添加" onclick="preAddRegionImage(3)" />
						<input type="button" value="点击查看示例图片1" onclick="jQuery.popMsg(jQuery('#regionImage3'),'示例图片-备选场地照片-正面','417','314')" />
						<input type="button" value="点击查看示例图片2" onclick="jQuery.popMsg(jQuery('#regionImage4'),'示例图片-备选场地照片-侧45度','417','314')" />
						<div id="divRegionImageFormContainer3"></div>
						<div id="divRegionImageContainer3"></div>
					</td>
				</tr>
			</table>
			<br />
			<div class="center-opertion">
					<html:submit>保存</html:submit>
				<input type="button" value="提交" onclick="realSubmit();" />
				<logic:equal name="regionForm" property="serial" value="1">
					<input type="button" value="上一步" onclick="toStep(-1)" />
				</logic:equal>
				<html:cancel>取消</html:cancel>
			</div>
			</div>
		</html:form>
		<form action="<c:url value="/site/user/regionImage.do?method=ajaxSave" />" method="POST" id="regionImageForm" enctype="multipart/form-data" style="display:none;" target="hiddenFrame">
			<input type="hidden" name="regionId" value="<c:out value="${regionForm.id}" />" id="currentRegionId" />
			<input type="hidden" name="typeCode" id="regionImageTypeCode" />
			<input type="file" name="file" id="file" />
			<input type="submit" value="提交" />
			<input type="button" value="取消" onclick="hideRegionImageForm()" />
		</form>
		<img id="regionImage1" src="<c:url value="/images/region-image1.jpg" />" style="display: none;" />
		<img id="regionImage2" src="<c:url value="/images/region-image2.jpg" />" style="display: none;width:614px;height:511px;" />
		<img id="regionImage3" src="<c:url value="/images/region-image3.jpg" />" style="display: none;" />
		<img id="regionImage4" src="<c:url value="/images/region-image4.jpg" />" style="display: none;" />
		<iframe name="hiddenFrame" style="display:none;"></iframe>
		<script type="text/javascript">
showDropDown(provincecitydistrict,["provinceId","cityId","districtId"],"drop");
		</script>
		<script type="text/javascript">
function toStep(num){
	if(num < 0)
		_g("direction").value="last";
	_g("mainForm").submit();
}

function calculateArea(){
	var w=_g("regionWidth").value;
	var d=_g("regionDepth").value;
	var a=_g("regionArea");
	if(w != null && w.length > 0
		&& d != null && d.length > 0){
		try{
			w=parseFloat(w);
			d=parseFloat(d);
			if(isNaN(w) || isNaN(d)){
				alert("请输入数字。");
				return;
			}
			a.value = Math.round(w * d * 100)/100;
		}catch(e){
			alert("请输入数字。");
		}	
	}
}

function realSubmit(){
	if(confirm("提交后将不能再修改，您确定要提交该申请吗？"))
		submitMethod('submit')
}
function checkedForm(){
	var fixedYear=_g("fixedYear");
	var sourceCode=_g("mainForm")["sourceCode"];	
	var sourCodeValue=getRadioControlValue(sourceCode);
	var flag=true;
	if(sourCodeValue!=''&&sourCodeValue=='2'){
		if(fixedYear.value==''){
			alert("请填写使用/租赁年限信息!");
			fixedYear.focus();
			flag=false;
		}
	}
	return flag;
}
function getRadioControlValue(component){
	var str="";
	if(component){
		if(component.length){
			for(var i=0;i<component.length;i++){
				if(component[i].checked){
					str=component[i].value;
					break;
				}
			}
		}else{					
			if(component.checked)
				str=component.value;
		}		 			
	}
	return str;
}

var contextUrl = "<c:url value='/'/>";
if(contextUrl.length>0) contextUrl = contextUrl.substr(0,contextUrl.length-1);

var regionIdVal = _g("currentRegionId").value;

//regionImage
var regionImageUrl = "<c:url value='regionImage.do' />";
var regionImageFormEl = _g("regionImageForm");

function preAddRegionImage(typeCode){
	if(regionIdVal == null || regionIdVal.length < 1)
		alert("请先保存当前表单，才能添加图片。")
	else{
		showRegionImageForm(typeCode);
	}
}

function resetRegionImageForm(){
	regionImageFormEl.reset();
	regionImageFormEl.id.value="";
	regionImageFormEl.typeCode.value="";
}

function showRegionImageForm(typeCode){
	resetRegionImageForm();
	_g("regionImageTypeCode").value = typeCode;
	_g("divRegionImageFormContainer"+typeCode).appendChild(regionImageFormEl);
	regionImageFormEl.style.display="";
}

function hideRegionImageForm(){
	resetRegionImageForm();
	regionImageFormEl.style.display = "none";
	_g('bd').appendChild(regionImageFormEl);
}

function showRegionImageHtml(entityJson){
	var divContainer = _g("divRegionImageContainer"+ entityJson.typeCode);
	var html = "";
	html += '<div id="img_'+entityJson.id+'"><img style="width:700px;" src="' + contextUrl + entityJson.attachPath + '" />';
	html += '<input type="button" value="删除" onclick="deleteRegionImage('+entityJson.id+');" /></div>';
	equalInnerHTML(html,function(div){
		divContainer.appendChild(div);
	})
}

function successRegionImage(jsonString){
	if(!refreshMessageJsonString(jsonString)) return false;
	hideRegionImageForm();
	
	var d = JSON.parse(jsonString);
	d = d.data;
	showRegionImageHtml(d);
}

function deleteRegionImage(id){
	if(confirm("确定要删除该记录吗？")) 
		_ajax(regionImageUrl + "?method=ajaxErase&id="+id, function(xhr){
			var data = JSON.parse(xhr.responseText);
			if(!refreshMessage(data)) return false;
			
			var i = _g("img_" + id);
			if(i) i.style.display = "none";
		})
}

function listRegionImage(){
	if(regionIdVal != null && regionIdVal.length > 0)
	_ajax(regionImageUrl + "?method=ajaxList&regionId=" + regionIdVal,function(xhr){
		var regionImageList = JSON.parse(xhr.responseText);
		if(!refreshMessage(regionImageList,false)) return false;
		regionImageList = regionImageList.data;

		if(regionImageList && regionImageList.length)
		for(var i = 0;i < regionImageList.length;i++){
			showRegionImageHtml(regionImageList[i]);
		}
	})
}
listRegionImage();
		</script>
	</body>
</html>
